<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle" :width="600">
    <ContentWrap>
      <el-table v-loading="loading" :data="list">
        <el-table-column label="产品名称" align="center" prop="productName" />
        <el-table-column label="应收数量" align="center" prop="receivableNum" />
        <el-table-column label="实际数量" align="center" prop="actualNum">
          <!-- <template #default="scope">
            <el-input v-model="scope.row.actualNum" size="small"></el-input>
          </template> -->
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
    <template #footer>
      <el-button :disabled="loading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
  import * as internalCodeApi from '@/api/hcxly/internalCode/Index'
  import { FormRules } from 'element-plus'

  defineOptions({ name: 'materialPickHang' });

  const { t } = useI18n() // 国际化
  const message = useMessage() // 消息弹窗

  const loading = ref(true) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据
  const dialogVisible = ref(false) // 弹窗的是否展示
  const dialogTitle = ref('') // 弹窗的标题
  const queryParams = reactive({
    pageNo: 1,
    pageSize: 10,
    id: undefined,
    name: undefined,
    materialCode: undefined,
    batchNumber: undefined,
    orderCode: '',
    batchCheckNumber: undefined
  })

  //打开弹窗
  const open = async (orderCode: string, type: string, code: string, materialStatus: string) => {
    dialogVisible.value = true
    dialogTitle.value = t('完善信息')
  }
  defineExpose({ open }) // 提供 open 方法，用于打开弹窗

  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await internalCodeApi.getInternalCode(queryParams)
      console.log(data)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }

  /** 提交出库操作 */
  const submitForm = async () => {
    // for(let i in list.value){
    //   // console.log(list.value[i].materialStatus)
    //   materialStatusArry.value.push(list.value[i].materialStatus)
    // }
    // if(materialStatusArry.value.every(item => item === '1')){
    //   outboundFlag.value = true
    // }
    // try {
    //   // 二次确认
    //   await message.exportConfirm()
    //   // 发起提交出库
    //   loading.value = true
    //   await materialPickApi.subOutbound(queryParams)
    //   message.success('出库成功！')
    // } catch {
    // } finally {
    //   loading.value = false
    // }
  }
</script>
